/**
 * @author yongzhi1u
 * @link https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/description/
 * @questionNo
 * @date 2024-02-20
 */

/**
 * Definition for a binary tree node.
 * class TreeNode {
 *     val: number
 *     left: TreeNode | null
 *     right: TreeNode | null
 *     constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.left = (left===undefined ? null : left)
 *         this.right = (right===undefined ? null : right)
 *     }
 * }
 */

function buildTree(preorder, inorder) {
  if (!preorder) {
    return null
  }
  if (preorder[0] === -1) {
    return new TreeNode(-1)
  }
  if (preorder.length === 1) {
    return [preorder[0]]
  }
  const root = new TreeNode(preorder[0])
  return root
};